package com.dfbz.utils;

import com.dfbz.common.Constant;

public class PageUtil {

    public static long getTotalPage(long totalCount){
        return totalCount % Constant.PAGE_SIZE == 0 ? totalCount / Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1;
    }

    public static long getStartPage(long currentPage){
        return currentPage % Constant.PAGE_SIZE == 0 ?  currentPage - Constant.PAGE_SIZE + 1 : (currentPage - currentPage % Constant.PAGE_SIZE) + 1;
    }

    public static long getEndPage(long currentPage, long totalCount){
        long startPage = getStartPage(currentPage);
        long totalPage = getTotalPage(totalCount);
        long endPage = startPage + Constant.PAGE_SIZE - 1;
        return endPage > totalCount ? totalPage : endPage;
    }
}
